//
//  TimestampToDate.m
//  U9WatchGame
//
//  Created by uuu9 on 2017/3/28.
//  Copyright © 2017年 Jason. All rights reserved.
//

#import "TimestampToDate.h"

@implementation TimestampToDate

+(NSString *)timeToDate:(long long)timestamp
{
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp]; //时间戳转date 转出来的是系统时间 和本地时间相差8小时
    NSDate *dateNow = [NSDate date];
    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd"];
    
    if ([[formater stringFromDate:confromTimesp] isEqualToString:[formater stringFromDate:dateNow]]) {
        [formater setDateFormat:@"今天  HH:mm:ss"];
    } else {
        [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    }
    
    NSString *date = [formater stringFromDate:confromTimesp];
    return date;
}


+(NSString *)timeToDateNoSecond:(long long)timestamp{
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp]; //时间戳转date 转出来的是系统时间 和本地时间相差8小时
    
    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"MM月dd日 HH:mm"];
    NSString *date = [formater stringFromDate:confromTimesp];
    return date;
}

@end
